package com.qf.hytrix.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Auther: Song
 * @Date: 2022-03-18 16:57
 */
@Service
public class HelloService {
    @Autowired
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "error",ignoreExceptions = ArithmeticException.class)
    public String hello() {
        int i = 1 / 0;
        String s = restTemplate.getForObject("http://storage/deduct", String.class);
        System.out.println("s = " + s);
        return s;
    }

    public String error(Throwable t) {
        System.out.println("t = " + t);
        return "error--->" + t.getMessage();
    }
}
